
use super::solution::Solution;
impl Solution {
    pub fn min_flips(grid: Vec<Vec<i32>>) -> i32 {
        let rev_m_ind = |ind:usize|grid[0].len() - ind - 1;
        let rev_n_ind=|ind:usize|grid.len() - ind - 1;
        let (mut m_size,mut n_size)=(0,0);
        for line in grid.iter() {
            for ind in 0..(line.len()+1)/2 {
                m_size+=if line[rev_m_ind(ind)]==line[ind] {0} else {1};
            }
        }
        for i in 0..grid[0].len(){
            for j in 0..(grid.len()+1)/2{
                n_size+=if grid[j][i]==grid[rev_n_ind(j)][i] {0} else {1};
            }
        }
        if m_size>n_size{
            n_size
        }else{
            m_size
        }
    }
}